package com.yupi.yuoj.model.vo;

import com.yupi.yuoj.model.entity.PopularTags;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
import org.springframework.beans.BeanUtils;

/**
 * 热门标签视图
 *
 * @author jingjin
 */
@Data
public class PopularTagsVO implements Serializable {

    /**
     * id
     */
    private Long id;

    /**
     * 标签名称
     */
    private String tagName;

    /**
     * 标签分类
     */
    private String category;

    /**
     * 使用次数
     */
    private Integer usageCount;

    /**
     * 热度分数
     */
    private Integer hotScore;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 分类文本
     */
    private String categoryText;

    /**
     * 热度等级
     */
    private String hotLevel;

    /**
     * 包装类转对象
     *
     * @param popularTagsVO
     * @return
     */
    public static PopularTags voToObj(PopularTagsVO popularTagsVO) {
        if (popularTagsVO == null) {
            return null;
        }
        PopularTags popularTags = new PopularTags();
        BeanUtils.copyProperties(popularTagsVO, popularTags);
        return popularTags;
    }

    /**
     * 对象转包装类
     *
     * @param popularTags
     * @return
     */
    public static PopularTagsVO objToVo(PopularTags popularTags) {
        if (popularTags == null) {
            return null;
        }
        PopularTagsVO popularTagsVO = new PopularTagsVO();
        BeanUtils.copyProperties(popularTags, popularTagsVO);
        
        // 设置分类文本
        if (popularTags.getCategory() != null) {
            switch (popularTags.getCategory()) {
                case "programming":
                    popularTagsVO.setCategoryText("编程");
                    break;
                case "technology":
                    popularTagsVO.setCategoryText("技术");
                    break;
                case "design":
                    popularTagsVO.setCategoryText("设计");
                    break;
                case "business":
                    popularTagsVO.setCategoryText("商业");
                    break;
                case "other":
                    popularTagsVO.setCategoryText("其他");
                    break;
                default:
                    popularTagsVO.setCategoryText("未知");
                    break;
            }
        }
        
        // 基于使用次数计算热度分数
        if (popularTags.getUsage_count() != null) {
            int usageCount = popularTags.getUsage_count();
            // 根据使用次数计算热度分数
            int hotScore = Math.min(100, usageCount); // 最高100分
            popularTagsVO.setHotScore(hotScore);
            
            // 设置热度等级
            if (hotScore >= 90) {
                popularTagsVO.setHotLevel("火爆");
            } else if (hotScore >= 70) {
                popularTagsVO.setHotLevel("热门");
            } else if (hotScore >= 50) {
                popularTagsVO.setHotLevel("普通");
            } else {
                popularTagsVO.setHotLevel("冷门");
            }
        }
        
        return popularTagsVO;
    }

    private static final long serialVersionUID = 1L;
}